

#pragma  once

#include <string>
#include <unordered_map>
#include <stdint.h>
#include <memory>
#include <mutex>
#include "ClassBase.h"


namespace FlameEngine
{
	//A simple pooled string class
	//Static functions are thread safe
	class UniqueString :public NonCopyAssignClass
	{
	public:
		//create UniqueString object
		static std::shared_ptr<UniqueString> Create(const char* str);
		
		inline uint64_t GetID() const {return m_id;}

		inline const std::string* GetStr() const {return &m_str;}

	private:
		//static member
		static std::mutex s_mutex;
		static std::unordered_map<uint64_t,std::shared_ptr<UniqueString> > s_uniqueStrings;
		static int32_t s_releaseCount;

		static void ReleaseUnusedString();

	private:
		uint64_t	m_id;
		const std::string m_str;

		UniqueString(uint64_t id, const char* str);
	};
}